package morning.cat.demo.generator;

import com.alibaba.druid.pool.DruidDataSource;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.generator.Generator;

/**
 * XXX
 *
 * @author mengzhang6
 * @date 2018/12/7 14:01
 */
public class GeneratorSample {

    public static void main(String[] args) {

        // base model 所使用的包名
        String baseModelPkg = "gernerator.base";
        // base model 文件保存路径
        String baseModelDir = PathKit.getWebRootPath() + "/src/gernerator/base";

        // model 所使用的包名
        String modelPkg = "gernerator";
        // model 文件保存路径
        String modelDir = baseModelDir + "/..";

        PropKit.use("mysql/config.properties");
        String driverClass = PropKit.get("jdbc.driver");
        String url = PropKit.get("jdbc.url");
        String username = PropKit.get("jdbc.username");
        String password = PropKit.get("jdbc.password");
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);

        // 生成
        Generator gernerator = new Generator(dataSource, baseModelPkg, baseModelDir, modelPkg, modelDir);
        gernerator.generate();
    }
}
